
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
//加载驱动       
Class.forName("org.mariadb.jdbc.Driver");

// 数据库连接信息
String dbURL = "jdbc:mariadb://10.220.140.102:3366/studb11";
String dbUser = "stua";
String dbPassword = "zHZUA65r";




// 建立连接
Connection conn = DriverManager.getConnection(dbURL, dbUser, dbPassword);
Statement stmt=conn.createStatement();
ResultSet rs = stmt. executeQuery("select*from 成都梦之旅文君楼庭院酒店（宽窄巷子店）");

        if (rs.next()) {
            // 用户验证成功，分配房间
            String roomSql = "UPDATE 成都梦之旅文君楼庭院酒店（宽窄巷子店） SET status = '已预订' WHERE status = '空置' LIMIT 1";
            Statement roomStmt = conn.createStatement();
            int rowsAffected = roomStmt.executeUpdate(roomSql);

            if (rowsAffected > 0) {
                out.println("登录成功，房间已分配。");
            } else {
                out.println("登录成功，但当前没有空置房间可供分配。");
            }
        } else {
            out.println("登录失败，用户名或密码错误。");
        }

%>